<script setup lang="ts">
import {
  Button, Cell, Image, Tag,
} from 'vant';
import { type PropType } from 'vue';

import type UserItem from '../models/UserItem';

defineProps({
  scope: {
    type: Object as PropType<{
      record: UserItem
      reload?: () => Promise<void>
    }>,
    default: () => ({}),
  },
  hide: {
    type: Function as PropType<() => void>,
    default: () => { },
  },
});

</script>

<template>
  <Cell>
    <div class="user-header">
      <Image round width="60" height="60"
        :src="scope.record.avatar" />
      <div class="user-info">
        <div class="name-row">
          <h3>
            {{ scope.record.nickName || scope.record.userName }}
          </h3>
        </div>
        <p class="user-id">ID:
          {{ scope.record.userId }}
        </p>
      </div>
    </div>

    <div class="info-card">
      <h4>账户信息</h4>
      <div class="info-grid">
        <div>
          <span class="label">可用余额</span>
          <span class="value">¥{{
            (scope.record.balance)
            }}</span>
        </div>
        <div>
          <span class="label">冻结金额</span>
          <span class="value">¥{{
            (scope.record.freezeBalance)
            }}</span>
        </div>
      </div>
    </div>

    <div class="info-card">
      <h4>个人信息</h4>
      <div class="info-list">
        <div class="info-item">
          <span class="label">手机号</span>
          <span
            class="value">{{ scope.record.phonenumber }}</span>
        </div>
        <div class="info-item">
          <span class="label">实名状态</span>
          <Tag
            :type="scope.record.realFlag ? 'success' : 'danger'"
            size="medium">
            {{ scope.record.realFlag ? '已认证' : '未认证' }}
          </Tag>
        </div>
        <div v-if="scope.record.realFlag"
          class="info-item">
          <span class="label">真实姓名</span>
          <span
            class="value">{{ scope.record.realName }}</span>
        </div>
        <div class="info-item" v-if="scope.record.realFlag">
          <span class="label">身份证</span>
          <span
            class="value">{{ scope.record.realId }}</span>
        </div>
      </div>
    </div>

  </Cell>
  <div
    class="footer van-hairline--top van-dialog__footer">
    <Button @click="hide" size="large"
      class=" van-dialog__cancel">取消</Button>
  </div>
</template>
<style lang="less" scoped>
.user-header {
  display: flex;
  align-items: center;
  padding: 16px;
  background: #f9f9f9;
  border-radius: 8px 8px 0 0;
}

.user-info {
  margin-left: 16px;
}

.name-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.name-row h3 {
  margin: 0;
  font-size: 18px;
  font-weight: bold;
}

.user-id {
  margin: 4px 0 0;
  color: #888;
  font-size: 13px;
}

.info-card {
  padding: 16px;
  border-bottom: 1px solid #f0f0f0;
}

.info-card h4 {
  margin: 0 0 12px;
  color: #333;
  font-size: 16px;
  font-weight: bold;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.info-grid>div {
  background: #f5f7fa;
  border-radius: 6px;
  padding: 10px;
}

.info-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.info-item {
  display: flex;
  justify-content: space-between;
}

.label {
  color: #666;
  font-size: 14px;
}

.value {
  color: #333;
  font-size: 14px;
  font-weight: 500;
  text-align: right;
}
</style>
